﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<sec:authentication property="principal" var="currentPrincipal" scope="page"/>

<fmt:setBundle basename="ApplicationMessage"/>
<fmt:setLocale value="zh_CN"/>

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp" %>
  <%@ include file="/WEB-INF/include/css.jsp" %>

</head>

<body class="ms-theme-blue">

<%@ include file="/WEB-INF/include/header.jsp" %>
<%@ include file="/WEB-INF/include/submenu.jsp" %>

<div class="container-fluid ms-container has-ms-sidemenu">

  <ol class="ms-breadcrumb breadcrumb">
    <li class="active">订单管理&nbsp;-&nbsp;订单列表</li>
  </ol>
  <div class="ms-content-layout">
    <div class="x-operation-bar no-margin no-bottom-border clearfix">

      <ul class="nav nav-tabs ms-nav-tabs" role="tablist">
<%--        <li role="presentation" class="${status.staying ? 'active' : ''}"><a href="${ctx.host}/orders?status=STAYING">保留预定</a>
        </li>--%>
        <li role="presentation" class="${status.unpaid ? 'active' : ''}"><a
          href="${ctx.host}/orders?status=UNPAID">待支付</a></li>
        <li role="presentation" class="${status.paid ? 'active' : ''}"><a href="${ctx.host}/orders?status=PAID">已支付</a>
        </li>
        <li role="presentation" class="${status.unRefunded ? 'active' : ''}"><a
          href="${ctx.host}/orders?status=UNREFUNDED">待退款</a></li>
        <li role="presentation" class="${status.canceled ? 'active' : ''}"><a href="${ctx.host}/orders?status=CANCELED">已取消</a>
        </li>
        <li role="presentation" class="${status.consumed ? 'active' : ''}"><a href="${ctx.host}/orders?status=CONSUMED">已核销</a>
        </li>
      </ul>
      <div class="ms-operation-bar no-margin no-bottom-border clearfix">
        <div class="ms-operation-group">
          <div class="pull-right">
            <a href="${ctx.host}/orders/search?status=${status}" data-target="#search"
               data-toggle="modal" class="btn ms-btn ms-btn-blue"> <i
              class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
            </a>
          </div>
        </div>
      </div>
      <table class="table table-hover ms-table">
        <thead>
        <tr>
          <th>订单号</th>
          <th>下单时间</th>
          <th>国家</th>
          <th>品牌</th>
          <th>取车-还车时间</th>
          <th>取车-还车地点</th>

          <c:if test="${status.canceled}">
            <th>取消时间</th>
            <th>退款时间</th>
          </c:if>

          <th>到付/预付</th>
          <th>订单金额(RMB)</th>
          <th>优惠结算金额(RMB)</th>
          <th>代理人</th>
          <td>提成</td>
          <th class="text-center">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${order}" var="order">
          <tr>
            <td>${order.code}</td>
            <td><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td>${persist.country(order.country).chineseName}</td>
            <td>${persist.supplier(order.brand).chineseName}</td>
            <td>
              <fmt:formatDate value="${order.pickupDate}" pattern="yyyy-MM-dd HH:mm"/><br/>
              <fmt:formatDate value="${order.returnDate}" pattern="yyyy-MM-dd HH:mm"/>
            </td>
            <td>${order.pickupLocationName}<br>${order.returnLocationName}</td>

            <c:if test="${order.status.canceled}">
              <td><fmt:formatDate value="${order.cancelTime}"></fmt:formatDate></td>
              <td><fmt:formatDate value="${order.refundTime}"></fmt:formatDate></td>
            </c:if>

            <td>${order.type.description}</td>
            <td>
<%--              <c:if test="${order.type.arrivepay}">
                <fmt:formatNumber value="${order.payPrice/100 * order.currentExchangeRate}" maxFractionDigits="2"
                                  type="number"/>
              </c:if>
              <c:if test="${order.type.prepay}">
                <fmt:formatNumber value="${order.payPrice/100 * order.currentExchangeRate + 0.499999999}"
                                  maxFractionDigits="0" type="number"/>.00
              </c:if>--%>
              ${order.type.arrivepay ? persist.exchangeRate(order.currencyCode).currencySymbol : "¥"} <fmt:formatNumber value="${order.cnyPayPrice}" pattern=".00"></fmt:formatNumber>
            </td>
            <td>
              <c:if test="${! empty order.userCouponId}">
                <fmt:formatNumber value="${persist.loadCnyPrice(order.id) < 0 ? '0.00':persist.loadCnyPrice(order.id)}"
                                  type="number" maxFractionDigits="2" pattern="0.00"/>
              </c:if>
            </td>
            <td>${order.agent.name}</td>
            <td>
                <c:if test="${not empty order.distributionRewardRecord}">
                  <fmt:formatNumber value="${order.distributionRewardRecord.amount / 100}" pattern="0.00"></fmt:formatNumber>
                </c:if>
                <c:if test="${empty order.distributionRewardRecord}">
                  无
                </c:if>
            </td>
            <td>
              <c:choose>
                <c:when test="${order.status.staying}">
                  <a href="${ctx.host}/orders/${order.id}/cancel" data-toggle="modal" data-target="#cancel">取消订单</a>&nbsp;&nbsp;
                  <a href="${ctx.host}/orders/${order.id}">详情</a>
                </c:when>
                <c:when test="${order.status.paid}">

                  <c:if test="${currentPrincipal.isFinanceUser() || currentPrincipal.isAdmin()}">
                    <a href="${ctx.host}/orders/${order.id}/consumed" data-toggle="modal"
                       data-target="#consumed">标记已核销</a>&nbsp;&nbsp;
                  </c:if>

                  <a href="${ctx.host}/orders/${order.id}/cancel" data-toggle="modal" data-target="#cancel">取消订单</a>&nbsp;&nbsp;
                  <a href="${ctx.host}/orders/${order.id}">详情</a>
                </c:when>
                <c:when test="${order.status.unpaid}">
                  <c:if test="${currentPrincipal.isFinanceUser() || currentPrincipal.isAdmin() || currentPrincipal.isSaler()}">
                    <a href="${ctx.host}/orders/${order.id}/pay" data-toggle="modal" data-target="#pay">标记已支付</a>&nbsp;&nbsp;
                  </c:if>

                  <!--<c:if test="${order.alamoCode == null}">
                  <a href="${ctx.host}/orders/${order.id}/cancel" data-toggle="modal" data-target="#cancel">取消订单</a>&nbsp;&nbsp;
                </c:if>
                  <c:if test="${order.alamoCode != null}">
                    <a href="javascript:void(0);" data-href="${ctx.host}/orders/${order.id}/cancel" data-order="${order.id}" data-agent="${order.agent.mobile}" class="order-button cancel-button disable cancelOrder">取消订单</a>
                  </c:if>-->
                  <a href="${ctx.host}/orders/${order.id}/cancel" data-toggle="modal" data-target="#cancel">取消订单</a>&nbsp;&nbsp;
                  <a href="${ctx.host}/orders/${order.id}">详情</a>
                </c:when>
                <c:when test="${order.status.unRefunded}">
                  <c:if test="${order.payStatus.paid}">
                    <c:if test="${currentPrincipal.isFinanceUser() || currentPrincipal.isAdmin()}">
                      <a href="${ctx.host}/orders/${order.id}/refunded" data-toggle="modal" data-target="#refunded">标记已退款</a>&nbsp;&nbsp;
                    </c:if>
                  </c:if>
                  <a href="${ctx.host}/orders/${order.id}">详情</a>
                </c:when>
                <c:when test="${order.status.consumed}">
                  <a href="${ctx.host}/orders/${order.id}">详情</a>
                </c:when>
                <c:when test="${order.status.canceled}">
                  <a href="${ctx.host}/orders/${order.id}">详情</a>
                </c:when>
              </c:choose>
            </td>
          </tr>
        </c:forEach>
        </tbody>
        <tfoot>
        <tr>
          <td colspan="14" class="no-vertical-padding">
            <div class="pull-left">
              <jsp:include page="/WEB-INF/include/page.jsp">
                <jsp:param name="url" value="${ctx.host}/orders"/>
                <jsp:param name="queryString" value="${queryString}"/>
              </jsp:include>
            </div>
          </td>
        </tr>
        </tfoot>
      </table>

    </div>
  </div>
</div>
<%@ include file="/WEB-INF/include/footer.jsp" %>
<%@ include file="/WEB-INF/include/script.jsp" %>
<d:resource type="script" root="${ctx.resource}/build"
            src="js/page/order/order-list.js"/>
<script type="text/javascript">
  require(['page/order/order-list'], function (page) {
    page.init({
      apiHost: "${config.apiHost}"
    })
  })
</script>

</body>
</html>